//* alien that follows you

alien_follower_images = new Images('follower',4);

function AlienFollower() {
  // contructor
  var that = new Alien();
  that.images = alien_follower_images;
  that.kind = 2;
  that.max_speed = 2+3*Math.random(); // followers have slightly random speed, just for fun
  that.credit = 20;
  
  // update 
  that.update = function() {
    // move 
    this.simpleMove();
    // follow ship if it is alive
    if (ship.life > 0) {
      var kx = ship.x - this.x;
      var ky = ship.y - this.y;
      var kk = Math.sqrt(kx*kx+ky*ky)
      this.dx = this.max_speed*kx/kk;
      this.dy = this.max_speed*ky/kk;
    } else {
      // if ship is destroyed, move randomly
      if (Math.random()<0.05) {
        this.dx = this.max_speed*(Math.random()-Math.random());
        this.dy = this.max_speed*(Math.random()-Math.random()); 
      }
    }
  }
  
  return that;
}

function AlienFollowers(ACount) {
  // create array of follower aliens
  var that = new Array();
  for (var i=0; i<ACount; i++)
      that.push(new AlienFollower());
  return that;  
}
